-- @owner: wan005
-- @date: 2024/10/8
-- @testpoint: 升级验证pipelined函数

--pre1:切换A库执行
@conn PrimaryDbAmode;

--step1:升级确认前创建pipelined函数;expect:失败
create or replace type type_0029 as (c1 integer, c2 tinyint);
create or replace type tb_type_0029 as table of type_0029;
create or replace function func_pipelined_029(count in number)
returns tb_type_0029 pipelined
as $$
declare result type_0029;
begin
for i in 1 .. count loop
result.c1 = 123;
result.c2 = 32;
pipe row(result);
end loop;
return;
end;
$$ language plpgsql;
/

--step2:升级后进行回滚pipelined函数;expect:失败
create or replace type type_0029 as (c1 integer, c2 tinyint);
create or replace type tb_type_0029 as table of type_0029;
create or replace function func_pipelined_029(count in number)
returns tb_type_0029 pipelined
as $$
declare result type_0029;
begin
for i in 1 .. count loop
result.c1 = 123;
result.c2 = 32;
pipe row(result);
end loop;
return;
end;
$$ language plpgsql;
/

--step3:升级确认后创建pipelined函数;expect:成功
create or replace type type_0029 as (c1 integer, c2 tinyint);
create or replace type tb_type_0029 as table of type_0029;
create or replace function func_pipelined_029(count in number)
returns tb_type_0029 pipelined
as $$
declare result type_0029;
begin
for i in 1 .. count loop
result.c1 = 123;
result.c2 = 32;
pipe row(result);
end loop;
return;
end;
$$ language plpgsql;
/

--step4:清理环境;expect:成功
drop type if exists tb_type_0029 cascade;
drop type if exists type_0029 cascade;
drop function if exists func_pipelined_029;
